﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;

namespace ObjRec
{
    class ArduinoConnect
    {
        SerialPort _serialPort;

        public ArduinoConnect(string com)
        {
            _serialPort = new SerialPort(com, 9600);
        }

        public bool Connect()
        {
            bool _connect = false;
            try
            {
                if (_serialPort.IsOpen) _serialPort.Close();
                _serialPort.Open();
                _connect = true;
            }
            catch (Exception ex) { throw ex; }
            return _connect;
        }

        public void Send(string s)
        {
            try
            {
                if (!_serialPort.IsOpen) Connect();
                _serialPort.Write(s);
            }
            catch (Exception ex) { throw ex; }
        }
    }
}
